/**
 * @filename:ChanpinServiceImpl Dec 20, 2023
 * @project Wonder Vue Admin Api  1.1.0
 * Copyright(c) 2022 Wonder Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.app.service.impl;

import com.wonder.app.domain.Chanpin;
import com.wonder.app.mapper.ChanpinDao;
import com.wonder.app.service.ChanpinService;
import com.wonder.app.request.ChanpinRequest;
import java.util.Date;
import java.util.Calendar;
import com.wonder.common.utils.StringUtils;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.common.AjaxResult;
import java.util.Map;
import java.util.HashMap;
import java.util.List;

import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.AccessType;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**   
 * @Description:TODO(产品名称服务实现)
 *
 * @version: 1.1.0
 * @author: Wonder
 * 
 */
@Service
public class ChanpinServiceImpl  extends ServiceImpl<ChanpinDao, Chanpin> implements ChanpinService  {


	@Autowired
	private ChanpinDao chanpinDao;


	@Autowired
	private ChanpinService chanpinService;

    /**
     * 验证产品名称信息
     * 
     * @param chanpin
     * @param type
     * @return String
     */
    @Override
    public String validate(Chanpin chanpin,String type){
    
    
       return "";
    }
    
    
    /**
	 * Description:产品名称分页返回
	 * @param request //检索条件
	 * @param page //分页参数
	 * @return IPage<Chanpin>   //分页记录
	 */
	@Override 
	public IPage<Chanpin> selectList(ChanpinRequest request, Page<Chanpin> page){
	    LambdaQueryWrapper<Chanpin> lambdaQueryWrapper = new LambdaQueryWrapper<>();
	    
	    if (null != request.getFid()) {
	       lambdaQueryWrapper.eq(Chanpin::getFid, request.getFid());
	      }               
             
        
		lambdaQueryWrapper.orderByDesc(Chanpin::getFid);	
		Page<Chanpin> selectPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
		return selectPage;
    }

	@Override
	public boolean chanpinTijiao(Long fid) {
		Chanpin chanpin = chanpinDao.selectById(fid);

		//获取提交和审核状态
		boolean tj = chanpin.getTijiao();
		boolean sh = chanpin.getShenhe();
		boolean res ;

		if(tj == true ){
			res = false;
		}else{
			chanpin.setTijiao(true);
			res = chanpinService.updateById(chanpin);
		}
		return res;
	}
	@Override
	public boolean chanpinChexiao(Long fid) {
		Chanpin chanpin = chanpinDao.selectById(fid);

		//获取提交和审核状态
		boolean tj = chanpin.getTijiao();
		boolean sh = chanpin.getShenhe();
		boolean res ;
		if(tj == true && sh == false){
			chanpin.setTijiao(false);
			res = chanpinService.updateById(chanpin);
			//true;
		}else{
			res = false ;
		}

		return res;
	}

	@Override
	public boolean chanpinShenhe(Long fid) {
		Chanpin chanpin = chanpinDao.selectById(fid);
		//获取提交和审核的状态
		boolean tj = chanpin.getTijiao();
		boolean sh = chanpin.getShenhe();
		boolean res ;
		Date currentDate = new Date();

		if(tj == true && sh == true  ){
			res = false;
		}
		else if(tj == true && sh == false ){
			chanpin.setShenhe(true);
			chanpin.setFAPPROVEDATE(currentDate);
			res = chanpinService.updateById(chanpin);
		}
		else{
			res = false;
		}
		return res;
	}
	@Override
	public boolean chanpinFanshenhe(Long fid) {
		Chanpin chanpin = chanpinDao.selectById(fid);
		//获取提交和审核的状态
		boolean tj = chanpin.getTijiao();
		boolean sh = chanpin.getShenhe();
		boolean res ;

		if(tj == true && sh == true ){
			chanpin.setTijiao(false);
			chanpin.setShenhe(false);
			chanpinService.updateById(chanpin);
			res = true;
		}else {
			res = false;
		}
		return res;
	}
}